package com.sze.volanmenetrendgyor;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class StationSpecialAdapter extends SimpleAdapter {
    private LayoutInflater mInflater;
    private ArrayList<StationClass> mItems;
    public int[] fields;
    public int header;

    public StationSpecialAdapter(Context context, ArrayList<StationClass> items, int header, int[] fields) {
	super(context, new ArrayList<HashMap<String, String>>(), header, new String[] {}, fields);
	// Cache the LayoutInflate to avoid asking for a new one each time.
	this.mItems = items;
	this.fields = fields;
	this.header = header;
	mInflater = LayoutInflater.from(context);
    }

    static class ViewHolder {
	TextView name;
    }

    @Override
    public int getCount() {
	return mItems.size();
    }

    public View getView(int position, View convertView, ViewGroup parent) {
	ViewHolder holder;
	if (convertView == null) {
	    convertView = mInflater.inflate(header, null);
	    holder = new ViewHolder();
	    holder.name = (TextView) convertView.findViewById(fields[0]);
	    convertView.setTag(holder);
	} else {
	    holder = (ViewHolder) convertView.getTag();
	}

	String item = mItems.get(position).name;
	if (item != null) {
	    holder.name.setText(item);
	} else {
	    holder.name.setText(" ");
	}

	return convertView;
    }
}